<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta charset="utf-8" />
	<title></title>
	<link href="../css/bootstrap.min.css" rel="stylesheet">
	<link href="../css/bootstrap-select.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="../css/bootstrap-treeview.min.css">
	<link href="../css/font-awesome.min.css" rel="stylesheet">
	<link href="../css/JyyCommon.css" rel="stylesheet">
	<link href="../css/JyyTable.css" rel="stylesheet">
	<link href="../css/JyyTree.css" rel="stylesheet">
	<link href="../css/JyyMsgBox.css" rel="stylesheet">
	<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="../js/jquery.form.min.js"></script> 
	<script type="text/javascript" src="../js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-paginator.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-treeview.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-select.js"></script>
	<script type="text/javascript" src="../js/jyy_modal.js"></script>
	<script type="text/javascript" src="../js/JyyCommon.js"></script>
	<script type="text/javascript" src="../js/JyyTable.js"></script>
	<script type="text/javascript" src="../js/JyyTree.js"></script>
	<script type="text/javascript" src="../js/JyyMsgBox.js"></script>
	<script type="text/javascript" src="../js/JyyLoading.js"></script>
	<script type="text/javascript" src="../js/echarts.js"></script>
	<script type="text/javascript" src="../../utils/CommonUtil.js"></script>
	<style>
	.heidenbt{
		display: none
	}
</style>
	<script type="text/javascript">
		var tree = null;
		var projectId =  getQueryString("projectId")||'88888888888';
		$(function(){
			getSelectDatas();
		});
		function selectData(){
			var yearSel =  $('#yearSel').val(); 
			var sectionName =  $('#sectionName').val();
			var exPower =  $('#exPower').val();
			var sectionPower =  $('#sectionPower').val();
			if(JyyCommon.isEmpty(yearSel)){
				JyyMsgBox.alert({ title:"警告", message:"[年]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			if(JyyCommon.isEmpty(sectionName)){
				JyyMsgBox.alert({ title:"警告", message:"[断面名称]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			if(JyyCommon.isEmpty(exPower) || (exPower > 100 || exPower < 0)){
				JyyMsgBox.alert({ title:"警告", message:"[极端大功率扣除概率]不可为空并且不能大于100小于0",type:"warning"}).on(function (e) {});
				return false;
			}
			if(JyyCommon.isEmpty(sectionPower) || (sectionPower > 100 || sectionPower < 0)){
				JyyMsgBox.alert({ title:"警告", message:"[断面输电电量扣除概率]不可为空并且不能大于100小于0",type:"warning"}).on(function (e) {});
				return false;
			}
			JyyModelLoading.start("sectionProAccumEchartDiv");
			$.when(getEcahtData(yearSel, sectionName,exPower,sectionPower, "selectSectionProAccumEchatData")).done(function(echatData){
				if(echatData.respData.isEmpty == 1) {
					initWord(echatData.respData);
					createEchat(echatData.respData);
				} else {
					JyyMsgBox.alert({ title:"信息", message:"数据库暂无相关数据",type:"info"}).on(function (e) {});
				}
				JyyModelLoading.end("sectionProAccumEchartDiv");
			});
		}
		
		function initWord(echartData) {
			$("#totalSection").html(echartData.firstData.count);
			$("#maxSection").html(echartData.firstData.max);
			$("#sumSection").html(echartData.firstData.sum);

			$("#exPowerSpan").html($("#exPower").val());
			$("#exSection").html(echartData.secondData.exSection);
			$("#proExSection").html(echartData.secondData.proExSection);
			$("#exMaxSection").html(echartData.secondData.exMaxSection);
			$("#proExMaxSection").html(echartData.secondData.proExMaxSection);
			$("#maxSectionDate").html(echartData.maxSectionDate);
			$("#allyearper").html(echartData.secondData.allyearper);
			
			$("#sectionPowerSpan").html($("#sectionPower").val());
			$("#sectionTidal").html(echartData.thirdData.sectionTidal);
			$("#maxSectionTidal").html(echartData.thirdData.maxSectionTidal);
			
		}

		function createEchat(echartData) {
			var id = "sectionProAccumEchart";
			var option = {};
			var xAxisName = "时间/小时";
			var yAxisName = "断面潮流/MW";
			var xAxisData = echartData.xAxisData;
			var curveData = echartData.curveData;
			option = {
			  	tooltip: {
			    	trigger: 'axis',
			    	position: function(point, params, dom, rect, size) {
			             //其中point为当前鼠标的位置，size中有两个属性：viewSize和contentSize，分别为外层div和tooltip提示框的大小
			             var x = point[0]; //
			             var y = point[1];
			             var viewWidth = size.viewSize[0];
			             var viewHeight = size.viewSize[1];
			             var boxWidth = size.contentSize[0];
			             var boxHeight = size.contentSize[1];
			             var posX = 0; //x坐标位置
			             var posY = 0; //y坐标位置

			             if (x < boxWidth) { //左边放不开
			                 posX = 5;
			             } else { //左边放的下
			                 posX = x - boxWidth;
			             }

			             if (y < boxHeight) { //上边放不开
			                 posY = 5;
			             } else { //上边放得下
			                 posY = y - boxHeight;
			             }

			             return [posX, posY];
			         }
			  	},
				toolbox: {
					show: true,
					right: 30,
				    itemSize: 20,
					itemGap: 12,
			        feature: {
			        	myTool: {
			        		show: true,
			        		title: "导出为Excel",
			        		icon: 'image://../images/excel.png',
			        		onclick: (o) => {
								var option = o.option;
								var dataSource = [];
								var dataType = "\uFEFF"; //解决乱码问题
								dataType += option.xAxis[0].name+",";  //添加表格的头
								if(option.series.length > 0) {
									for(var i = 0;i < option.series.length;i++) {
										dataType += option.series[i].name+","
									}
									dataType = dataType.substr(0, dataType.length-1)
								}
								dataType += '\n'; // 以上是导出的Excel文件头部

								for(var i = 0;i < option.xAxis[0].data.length;i++) {
									var arr = [];
									for(var j = 0;j < option.series.length+1;j++) {
										if(j == 0) {
											arr.push(option.xAxis[0].data[i]);
										} else {
											arr.push(option.series[j-1].data[i]);
										}
									}
									dataSource.push(arr);
								}
								// 从dataSource中取出数据存入数据源（dataType）
								dataSource.map(item => dataType += `${item.join(',')}\n`); 
								// 使用Blob，获得二进制实例
								const csvData = new Blob([dataType], {
								    type: 'text/csv'
								});
								// 创建a标签
								const _a = document.createElement('a');
								_a.href = URL.createObjectURL(csvData);
								_a.target = '_blank';
								_a.download = `断面潮流概率累积曲线.csv`;
								document.body.appendChild(_a);
								_a.click();
								document.body.removeChild(_a);
		                   	},
			        	},
			        	saveAsImage: {name:"断面潮流概率累积曲线",icon:"image://../images/downpic.png"}
			        }
			    },
			  	grid: {
			    	left: '3%',
			    	right: '8%',
			    	bottom: '12%',
			    	containLabel: true
			  	},
			  	xAxis: [{
			    	type: 'category',
			    	name: xAxisName,
			      	data: xAxisData
			    }],
			  	yAxis: [{
			      	type: 'value',
			      	name: yAxisName,
			      	boundaryGap: [0, '30%']
			    }],
			    dataZoom: [{
			    	type: 'inside',
			    	start: 0,
			    	end: 10
				},{
				    start: 0,
				    end: 10
			    }],
			  	series: [{
					type: 'line',
				    data: echartData.seriesData,
				    name: "断面潮流",
				    smooth: 0.4,
				    symbol: 'none',
				    markPoint: {
				        data: [{   value: '扣除极端\n大功率', xAxis: curveData.redX, yAxis: curveData.redY,itemStyle:{
			        		color:'red'
			        	} },
				        	{   value: '扣除断面\n输电电量', xAxis: curveData.blueX, yAxis: curveData.blueY ,itemStyle:{
				        		color:'blue'
				        	}}],
				        	symbolSize:88,
				        	
				      },
				    markLine: {
				        label: { show: true },
				        data: [{
				        	xAxis: curveData.redX ,
				        	lineStyle: { color:'#FF5758' }
				        },{
				        	yAxis: curveData.redY,
				        	lineStyle: { color:'#FF5758' }
				        },{
				        	xAxis: curveData.blueX ,
				        	lineStyle: { color:'#7F83FE' }
				        },{
				        	yAxis: curveData.blueY,
				        	lineStyle: { color:'#7F83FE' }
				        }]
				    }
				}]
			};
			var chartDom = document.getElementById(id);
			var myChart = echarts.init(chartDom);
			myChart.clear();
			myChart.setOption(option);
			window.addEventListener("resize", () => {
				if(myChart){
					myChart.resize()
				}
			})
		}
		
		//查询
		function select(){
			selectData();
		}

		function getQueryString (name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			return r ? unescape(r[2]) : null;
		}

		function getSelectDatas(){
			$.ajax({
				url: "Sample/getSectionTotalAnaly",
				type:'POST',
				async:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId }),
				contentType:"application/json",
		        success:function(data){
					var content = '';
					$.each(data.respData.sectionname,function(i,n){
						content += "<option value='" + n + "'>"+ n +"</option>";
					});
					$("#sectionName").html(content);

					var content1 = '';
					$.each(data.respData.iyear,function(i,n){
						content1 += "<option value='" + n + "'>"+ n +"</option>";
					});
					$("#yearSel").html(content1);
					$('.selectpicker').selectpicker('refresh');
					selectData();
		        }
			});
		}
		
		function getEcahtData(yearSel, sectionName,exPower,sectionPower, method){
			var res = $.ajax({
				url: "Sample/"+method,
				type:'POST',
				cache:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId, yearSel : yearSel,sectionName : sectionName,
					exPower : exPower, sectionPower : sectionPower }),
				contentType:"application/json",
	            success:function(data){
					return data;
	            }
			});
			return res;
		}

		function invoke(url, args, callback){
			var r, op = {
					url: '../g/service/Sample/' + url,
					type:'POST',
					cache:false,
					async:true,
					dataType:'json',
					data:args ? JSON.stringify(args) : null,
					contentType:"application/json"
				};
			if(typeof callback == 'function'){
				op.success = function(data){
					if(data.error)return alert(data.error);
					callback(data);
				}
			} else {
				op.async = false;
				op.success = function(data){
					r = data
				};
			}
			$.ajax(op);
			if(r)if(r.error){
				alert(r.error);
				return null;
			}
			return r;
		};
	</script>
<style type="text/css">
	body, html{
		width: 100%;
		height: 100%;
	}
	.selBtn {
		float:left;
		margin-left:20px;
		height:30px;
		width:70px;
		background-color:#1890FF;
		border-radius:5px;
		border: 0px;
		color:white;
	}
	.selBtn:hover {
		background-color: #00BFFF;
	}
	.shadow {
		box-shadow: 0 0.05rem 1rem rgba(0,0,0,0.15)!important;
		border-radius: 0.25rem!important;
		margin-left: 20px;
		margin-bottom: 20px;
	}
	.bootstrap-select:not(.input-group-btn), .bootstrap-select[class*="col-"] {
		float: left;
	}
	#totalData span {
		font-size: 15px;
		font-weight: bold;
	}
</style>
</head>
<body>
<div style="overflow-y: auto;width: 100%;height: 100%;">
	<div style="height: 50px;width: calc(100% - 20px);">
		<div class="col-md-12" style="padding-left: 5px;padding-right: 5px;margin-top: 10px;margin-left: 20px;">
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;padding: 0px;width: 30px;font-weight: normal;">年</label>
			<select class="form-control" id="yearSel" style="float: left;margin-top: -3px;padding: 5px;width: 120px;font-weight: normal;"></select>
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 20px;padding: 0px;width: 60px;font-weight: normal;">断面名称</label>
			<select class="form-control" id="sectionName" style="float: left;margin-top: -3px;padding: 5px;width: 150px;font-weight: normal;"></select>
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 20px;padding: 0px;width: 30px;font-weight: normal;">扣除</label>
			<input id="exPower" class="form-control" style="float: left;margin-top: -3px;padding: 5px;width: 50px;font-weight: normal;" value=0>
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 5px;padding: 0px;width: 130px;font-weight: normal;">%概率极端大功率, 扣除</label>
			<input id="sectionPower" class="form-control" style="float: left;margin-top: -3px;padding: 5px;width: 50px;font-weight: normal;" value=0>
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 5px;padding: 0px;width: 100px;font-weight: normal;">%断面输电电量。</label>

			<button class="selBtn" onclick=select()>查询</button>
		</div>
	</div>
	<div id="sectionProAccumEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">断面潮流概率累积曲线</span>
		</p>
		<div id="totalData" style="width: calc(100% - 40px);margin-left: 40px;">
			<p>共<span id="totalSection">0</span>个断面潮流值，断面潮流最大值为<span id="maxSection">0</span>万千瓦，潮流最大时刻为<span id="maxSectionDate"></span>，断面输电量为<span id="sumSection">0</span>亿千瓦时，</p>
			<p>扣除<span id="exPowerSpan">0</span>%概率极端大功率，断面潮流在<span id="exSection">0</span>万千瓦以内，为最大潮流的
			<span id="proExSection">0</span>%；超过该值的越线部分电量为<span id="exMaxSection">0</span>亿千瓦时，占断面输电量<span id="proExMaxSection">0</span>%，占全年新能源发电量的<span id="allyearper">0</span>%。</p>
			<p>扣除<span id="sectionPowerSpan">0</span>%断面输电电量，断面潮流在<span id="sectionTidal">0</span>万千瓦以内，为最大潮流的<span id="maxSectionTidal">0</span>%。</p>
		</div>
		<div id="sectionProAccumEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
</div>
</body>
</html>